Call it by assigning the particular form's Id to argument, formID.
To display Ajax loader in the specified HTML tag element, such as <span>, <div>, etc.
tagID, the Id of the element you want to display the loader;
loader, the string/<image> that you want it to be displayed.
Simply call it once Ajax is done.
To clear the Ajax loader by assigning the Id to tagID
The Options
There are some options you will need to set in the argument when calling on function to make Ajax lives. The options are in the key/value pairs, which reside in a curly bracket {}. Here is the list:
Optional
Format: String
The Id that you might be using it for displaying the returned data from the server.
Mandatory
Format: String
The static or remote page that you're going to call for sending and processing data.
Optional
Format: String (serialized)
The data that will be sent to the server; *must* be in serialized format. (name1=value1&name2=value2&name3=value3&nameN=valueN...)
Optional
Format: String
The method of sending data. Holds the "GET" or "POST" value. It's set as "GET" by default if not specified.
Optional
Format: String
Values:
"json" - get the returned JSON data from server
"xml" - get the returned XML data from server
If 'type' is not specified, plain text data format will be used as default.
Mandatory
Format: Function
Taking one argument, result
Ajax will pass the processed data to this callback function. The returned data will be assigned to result argument.
You can then proceed to dealing the processed data in order to meet your needs.
How bAjax Works
It's easy to use bAjax for calling Ajax.
To do so, you will need to include "bajax.js" file in the first place (Normally within <head> </head> tag). Once you're done, just invoke this function:
The way to include "bajax.js" could be like so:
(make sure the path is correct and tally with your own application's directory)
The minimal condition for using this function is as follows:
bajax.init({
url: "my_ajax_action_page.php",
callback: function(result){
/*
the processed data will be passed to "result" argument,
do your works here, or even go further
*/
}
});
This is the simplest way for using init function to get your Ajax's result. Once you have had the processed result in the callback function, you're allowed to do more and even proceed to your own JavaScript's functions.
Please refer to the "Demo" to see more usage of this function.